<?php
namespace App\Services;


use App\Notifications\IncreHeightCode;
use App\Notifications\UsageNoticeCode;
use App\Notifications\VerificationCode;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Notification;
use Leonis\Notifications\EasySms\Channels\EasySmsChannel;
use Overtrue\EasySms\PhoneNumber;

class SmsService {

    public static function sendYzm($phone) {
        $code = generate_code(5);
        Notification::route(
            EasySmsChannel::class,
            new PhoneNumber($phone, 86)
        )->notify(new VerificationCode($code));
        Cache::set("yzm_" . $phone, $code, 300);
        return $code;
    }

    public static function validYzm($phone, $code) {
        return Cache::get("yzm_" . $phone) == $code;
    }

    public static function usageNotice($phone) {
        Notification::route(
            EasySmsChannel::class,
            new PhoneNumber($phone, 86)
        )->notify(new UsageNoticeCode(11));
    }

    public static function incrementHeight($phone) {
        Notification::route(
            EasySmsChannel::class,
            new PhoneNumber($phone, 86)
        )->notify(new IncreHeightCode(11));
    }


}